package com.lfs.admin.controller.dataPackage;

import com.lfs.admin.model.entity.ResponseEntity;
import com.lfs.admin.model.vo.AgtWalletDetailSummaryVO;
import com.lfs.admin.service.AgentInfoService;
import com.lfs.admin.service.AgtWalletInfoService;
import com.lfs.base.dto.Result;
import com.lfs.base.dto.ResultObject;
import com.lfs.interfaces.wallet.service.AgentWalletService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/wallet/summary")
@Slf4j
public class WalletSummaryController {

    @Autowired
    private AgtWalletInfoService walletService;


    @PostMapping("/generate")
    @ApiOperation(value = "手动生成指定日期汇总数据")
    public Result<String> generateSummary(@RequestBody AgtWalletDetailSummaryVO agtWalletDetailSummaryVO) {
        try {
            walletService.generateDailySummaryForDate(agtWalletDetailSummaryVO);
            return ResultObject.successMessage("汇总数据生成成功");
        } catch (Exception e) {
            log.info("汇总数据生成失败,error={}", e.getMessage());
            return ResultObject.serverErrorObject(e.getMessage());
        }
    }

    @PostMapping("/regenerate")
    @ApiOperation(value = "重新生成某日指定汇总数据")
    public Result<String> regenerateSummary(@RequestBody AgtWalletDetailSummaryVO agtWalletDetailSummaryVO) {
        try {
            walletService.regenerateDailySummary(agtWalletDetailSummaryVO);
            return ResultObject.successMessage("汇总数据重新生成成功");
        } catch (Exception e) {
            log.error("汇总数据重新生成失败,error={}", e.getMessage());
            return ResultObject.serverErrorObject("汇总数据重新生成失败:" + e.getMessage());
        }
    }
}